import { defineStore } from "pinia";


export const useStore = defineStore('main',{
    state : () => {
        return {
            curTitle : '',
            menuTabs : [],
            dataList : [],
            lastId : ''
        }
    },
    actions : {
        setLastId(id){
            this.lastId = id;
        },
        setMenuTabs(tabs){
            this.menuTabs = tabs
        },
        getMenuTabs(){
            if(this.menuTabs.length != 0){
                return this.menuTabs[0]
            }
            return this.menuTabs;
        },
        getDataList(){
            return this.dataList
        },
        setDataList(list){
            if(Array.isArray(list) && list.length > 0){
                list.forEach((item)=>{
                    this.dataList.push(item)
                })
            }
            else{
                this.dataList = [];
            }
        },
        updataCurTitle(title){
            this.curTitle = title
        },
        getCurTitle(){
            return this.curTitle
        }
    }
})